import React, { PropTypes } from 'react';
import Head from './head';
import AccoutMsg from './accoutMsg';
import request from '../../../../utils/request';
import MenuItemList from './menuItemList';
import {Toast} from 'antd-mobile';

const propTypes = {

};
class MyMenu extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            userMsg:{}
        };
    }
    componentDidMount() {


    }

    componentWillMount(){

        const isLogin = localStorage.getItem("isLogin");

        if (isLogin === '0'){//未登录
            this.state.userMsg.user_name = '';
        }else if (isLogin === '1'){
            this.state.userMsg.user_name = localStorage.getItem("userName");
            request('UserDetailsService','findByUserName', {
                method: 'POST',
                body: {
                    userName: this.state.userMsg.user_name
                },
            }).then((value) => {
                if (value.data.result === 0){
                    const { userInfo } = value.data.resultData;
                    this.setState({userMsg:userInfo});

                }else if (value.data.result === 1){
                    Toast.info("请求失败，请稍后再试！",1);
                }
            });
        }
    }

    render() {
        return (
            <div>
                <div style={{float:'relative'}}>
                    <Head />
                    <div className="accoutMsgDiv">
                        <AccoutMsg userMsg={this.state.userMsg}/>
                    </div>
                </div>
                <div>
                    <div style={{marginTop:'200px'}}>
                        <MenuItemList userMsg={this.state.userMsg}/>
                    </div>
                </div>

            </div>
        );
    }
}

MyMenu.propTypes = propTypes;

export default MyMenu;